package datamining.visualisation;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.Properties;

import javax.swing.JPanel;

import settings.Settings;
import javax.swing.JRadioButton;
import javax.swing.JSlider;
import javax.swing.JComboBox;
import javax.swing.JPasswordField;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JLabel;
import javax.swing.JToggleButton;
import javax.swing.ButtonGroup;
import javax.swing.JTextField;
import java.awt.BorderLayout;
import javax.swing.JButton;

/** 
 * 创建于 2012-11-22 上午11:14:01
 * 
 * @author xujinghu (jinghuxu@nudt.edu.cn)
 * 
 * Copyright 2012 xujinghu
 * 
 * Lisence: Apache
 */
public class ControlPanel extends JPanel implements ActionListener,
PropertyChangeListener {
	
	private Properties props = null;
	private final ButtonGroup buttonGroup = new ButtonGroup();
	private JTextField textField_support;
	private final PropertyChangeSupport cpListeners;
	
	public ControlPanel(Properties props){
		this.props = props;
		cpListeners = new PropertyChangeSupport(this);
		
		setLayout(new BorderLayout(0, 0));
		
		JPanel panel_parameters = new JPanel();
		add(panel_parameters);
		GridBagLayout gbl_panel_parameters = new GridBagLayout();
		gbl_panel_parameters.columnWidths = new int[]{108, 1, 91, 19, 28, 67, 0};
		gbl_panel_parameters.rowHeights = new int[]{24, 16, 23, 23, 0, 0, 0, 0, 0};
		gbl_panel_parameters.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		gbl_panel_parameters.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		panel_parameters.setLayout(gbl_panel_parameters);
		
		JLabel label_algorithm = new JLabel("算法：");
		GridBagConstraints gbc_label_algorithm = new GridBagConstraints();
		gbc_label_algorithm.anchor = GridBagConstraints.WEST;
		gbc_label_algorithm.insets = new Insets(0, 0, 5, 5);
		gbc_label_algorithm.gridx = 0;
		gbc_label_algorithm.gridy = 1;
		panel_parameters.add(label_algorithm, gbc_label_algorithm);
		
		JComboBox comboBox_algorithm = new JComboBox();
		GridBagConstraints gbc_comboBox_algorithm = new GridBagConstraints();
		gbc_comboBox_algorithm.anchor = GridBagConstraints.WEST;
		gbc_comboBox_algorithm.insets = new Insets(0, 0, 5, 5);
		gbc_comboBox_algorithm.gridwidth = 2;
		gbc_comboBox_algorithm.gridx = 1;
		gbc_comboBox_algorithm.gridy = 1;
		panel_parameters.add(comboBox_algorithm, gbc_comboBox_algorithm);
		comboBox_algorithm.setModel(new DefaultComboBoxModel(new String[] {"AprioriAll", "Prefix", "Spade"}));
		
		JLabel label_confidence = new JLabel("置信度：");
		GridBagConstraints gbc_label_confidence = new GridBagConstraints();
		gbc_label_confidence.anchor = GridBagConstraints.WEST;
		gbc_label_confidence.insets = new Insets(0, 0, 5, 5);
		gbc_label_confidence.gridx = 0;
		gbc_label_confidence.gridy = 2;
		panel_parameters.add(label_confidence, gbc_label_confidence);
		
		JSlider slider_confidence = new JSlider();
		GridBagConstraints gbc_slider_confidence = new GridBagConstraints();
		gbc_slider_confidence.anchor = GridBagConstraints.WEST;
		gbc_slider_confidence.insets = new Insets(0, 0, 5, 5);
		gbc_slider_confidence.gridwidth = 4;
		gbc_slider_confidence.gridx = 1;
		gbc_slider_confidence.gridy = 2;
		panel_parameters.add(slider_confidence, gbc_slider_confidence);
		
		JLabel label_ConfidenceNow = new JLabel("？%");
		GridBagConstraints gbc_label_ConfidenceNow = new GridBagConstraints();
		gbc_label_ConfidenceNow.anchor = GridBagConstraints.NORTHWEST;
		gbc_label_ConfidenceNow.insets = new Insets(0, 0, 5, 5);
		gbc_label_ConfidenceNow.gridx = 5;
		gbc_label_ConfidenceNow.gridy = 2;
		panel_parameters.add(label_ConfidenceNow, gbc_label_ConfidenceNow);
		
		JLabel label_support = new JLabel("支持度：");
		GridBagConstraints gbc_label_support = new GridBagConstraints();
		gbc_label_support.anchor = GridBagConstraints.WEST;
		gbc_label_support.insets = new Insets(0, 0, 5, 5);
		gbc_label_support.gridx = 0;
		gbc_label_support.gridy = 3;
		panel_parameters.add(label_support, gbc_label_support);
		
		textField_support = new JTextField();
		GridBagConstraints gbc_textField_support = new GridBagConstraints();
		gbc_textField_support.anchor = GridBagConstraints.WEST;
		gbc_textField_support.insets = new Insets(0, 0, 5, 5);
		gbc_textField_support.gridwidth = 2;
		gbc_textField_support.gridx = 1;
		gbc_textField_support.gridy = 3;
		panel_parameters.add(textField_support, gbc_textField_support);
		textField_support.setColumns(10);
		
		JLabel label_search = new JLabel("子图搜索方式：");
		GridBagConstraints gbc_label_search = new GridBagConstraints();
		gbc_label_search.anchor = GridBagConstraints.WEST;
		gbc_label_search.insets = new Insets(0, 0, 5, 5);
		gbc_label_search.gridx = 0;
		gbc_label_search.gridy = 4;
		panel_parameters.add(label_search, gbc_label_search);
		
		JRadioButton rdbtnGraphBased = new JRadioButton("Graph based");
		GridBagConstraints gbc_rdbtnGraphBased = new GridBagConstraints();
		gbc_rdbtnGraphBased.anchor = GridBagConstraints.NORTHEAST;
		gbc_rdbtnGraphBased.insets = new Insets(0, 0, 5, 5);
		gbc_rdbtnGraphBased.gridwidth = 2;
		gbc_rdbtnGraphBased.gridx = 1;
		gbc_rdbtnGraphBased.gridy = 4;
		panel_parameters.add(rdbtnGraphBased, gbc_rdbtnGraphBased);
		buttonGroup.add(rdbtnGraphBased);
		
		JRadioButton rdbtnEmbeddingBased = new JRadioButton("Embedding Based");
		GridBagConstraints gbc_rdbtnEmbeddingBased = new GridBagConstraints();
		gbc_rdbtnEmbeddingBased.insets = new Insets(0, 0, 5, 0);
		gbc_rdbtnEmbeddingBased.anchor = GridBagConstraints.NORTHWEST;
		gbc_rdbtnEmbeddingBased.gridwidth = 3;
		gbc_rdbtnEmbeddingBased.gridx = 1;
		gbc_rdbtnEmbeddingBased.gridy = 5;
		panel_parameters.add(rdbtnEmbeddingBased, gbc_rdbtnEmbeddingBased);
		buttonGroup.add(rdbtnEmbeddingBased);
		
		JButton Button_search = new JButton(props.getProperty("button_Start"));	//开始搜索按钮
		Button_search.addActionListener(this);
		add(Button_search, BorderLayout.SOUTH);
	}

	@Override
	public void propertyChange(PropertyChangeEvent evt) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void actionPerformed(ActionEvent event) {
		final String command = event.getActionCommand();
		System.err.println(this.getClass().getName()
				+ " action performed " + command);
		
		if (command.equals(props.getProperty("button_Start"))) {
			cpListeners.firePropertyChange(UIEvents.start, 0, 1);
		}
		
	}
	
	@Override
	public void addPropertyChangeListener(final PropertyChangeListener l) {
		cpListeners.addPropertyChangeListener(l);
	}

	@Override
	public void addPropertyChangeListener(final String str,
			final PropertyChangeListener l) {
		cpListeners.addPropertyChangeListener(str, l);
	}

}
